<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-date-picker @change="changeScrapMonth" v-model="scrapMonth" format="YYYY-MM" value-format="YYYY-MM" type="month" placeholder="请选择报废到期日期"/>
				<el-switch @change="changeOld" v-model="isContainOldScrap" inline-prompt active-text="包含以往过期资产" inactive-text="不包含以往过期资产"
				/>
				<el-checkbox style="margin-left: 5px;" @change="changeNetValue" size="large" v-model="isNetValueZero">净值为0资产(购置日期大于等于2年)</el-checkbox>
				<el-checkbox @change="changeHuaShi" size="large" v-model="isHuaShi">华士盘亏资产购置大于5年</el-checkbox>
				<fsButton style="margin-left: 5px;" ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
			<div class="right-panel">
				<ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="code" placeholder="请输入资产编码" :fixed-param="fixedParams" :initParams="searchParams"></ex-search>
			</div>
		</el-header>
		<el-main class="nopadding">
			<ex-table id="checkTaskTable" :auto-refresh="false" ref="table" :tablename="'报废到期查询'" :columns="columns" :url="this.$API.asset.asset.list.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
		</el-main>
	</el-container>
	<data-card ref="dataCard"></data-card>
</template>

<script>
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExTreeNavigation from "@/components/exSearchTree/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import scSelectFilter from "@/components/scSelectFilter/index.vue";
import tool from "@/utils/tool";
import DataCard from "@/views/asset/card/card.vue";
import moment from "moment";
import globalparam from "@/constant/model/globalparam";
import BaseTemplate from "@/utils/baseTemplate";
import useTabs from "@/utils/useTabs";
import router from "@/router";
export default {
	name: '报废到期查询',
	components: {
		DataCard,
		scSelectFilter,
		ExSearchTree,
		ExTreeNavigation,
		ExSearch,
		ExTable,
	},
	data() {
		return {
			dialog: {
				save: false,
				permission: false,
			},
			apiObj: [],
			buttons: [
				{name: "导出", icon: "el-icon-download", click: "export", type: "info", permission: "export"},
			],
			searches: [],
			columns: [
				{code: "assetStatusId", name: "资产状态", width:"65",formatter:"DICT",key: "ASSET_STATUS"},
				{code: "code", name: "资产编码", width:"135",click:"show1"},
				{code: "financialCode", name: "财务编码", width:"170"},
				{code: "name", name: "资产名称", width:"200"},
				{code: "boughtDate", name: "购置日期", width:"110",formatter: "DATE"},
				{code: "workingLife", name: "使用月份", width:"150"},
				{code: "mainCategoryCode", name: "资产大类",width:"110", formatter:"DICT",key: "FamsAssetCategory"},
				{code: "assetCategoryId", name: "资产小类",width:"180", formatter:"DICT",key: "FamsAssetCategory"},
				{code: "storePlaceId", name: "资产位置",width: "120", formatter:"DICT",key: "FamsPosition"},
				{code: "brand", name: "品牌", width:""},
				{code: "model", name: "规格型号", width:""},
				{code: "serialCode", name: "资产序列号", width:"150"},
				{code: "assetCount", name: "数量", width:"50",summary:true},
				{code: "originalValue", name: "资产原值", width:"100",summary:true},
				{code: "netValue", name: "资产净值", width:"100",summary:true},
				{code: "usingMenId", name: "使用人", width:"110",formatter: "DICT",key: "SysUser"},
				{code: "usingDepartmentId", name: "使用部门", width:"150",formatter: "DICT",key: "SysOrganization"},
				{code: "dutyDepartmentId", name: "管理部门", width:"150",formatter: "DICT",key: "SysOrganization"},
				{code: "createTime", name: "入库日期", width:"110",formatter: "DATE"},
				{code: "recipientOnDate", name: "领用日期", width:"110",formatter: "DATE"},
			],
			parentLevelCode:"",
			assetIds:[],
			loading: false,
			scrapMonth: moment(new Date()).format("YYYY-MM"),
			isContainOldScrap: false,
			isNetValueZero: false,
			isHuaShi: false,
			deptIds:this.$TOOL.current.manageDeptIds(),
			manageCategoryIds: this.$TOOL.current.manageAssetCategoryIds(),
			fixedParams: {
				excludeStatus:['delete','scrap'],
				deptIds:this.$TOOL.current.manageDeptIds(),
				manageCategoryIds: this.$TOOL.current.manageAssetCategoryIds(),
			},
			assetStatus: [],
			searchParams:{},
			assetStatisticsRange: '',
			loginUsers: tool.current.user(),
		}
	},
	created() {
		//如果是通过跳转过来的，标签的名称设置为跳转后的标题
		let route = router.currentRoute.value;
		if(route.meta){
			this.title=route.meta.title;
		}
		let routeParams = this.$store.state.routeParams[this.$route.params.key];
		if(routeParams){
			if(routeParams.title){
				useTabs.setTitle(routeParams.title);
				document.title = routeParams.title;
			}
			this.buttons = [
				{name: "导出", icon: "el-icon-download", click: "export", type: "info"},
			]
			if (routeParams.fixedParams) {
				Object.assign(this.fixedParams,routeParams.fixedParams);
				if(routeParams.fixedParams.assetStatisticsRange){
					this.assetStatisticsRange = routeParams.fixedParams.assetStatisticsRange;
				}
				if(routeParams.fixedParams.isContainOldScrap){
					this.isContainOldScrap = routeParams.fixedParams.isContainOldScrap;
				}
				if (routeParams.fixedParams.deptIds){
					this.deptIds = routeParams.fixedParams.deptIds;
				}
			}
			if (routeParams.searchParams) {
				Object.assign(this.searchParams,routeParams.searchParams);
			}
		}
	},
	async mounted() {
		if(!this.fixedParams.assetStatisticsRange){
			this.assetStatisticsRange = await this.$cache.data.loadGlobalParam(globalparam.assetStatisticsRange.paramCode);
			this.fixedParams.assetStatisticsRange = this.assetStatisticsRange;
		}
		let assetStatusMap = await this.$cache.dic.options("ASSET_STATUS");
		if(assetStatusMap){
			assetStatusMap.forEach(item=>{
				if(item.value !=="delete" && item.value !=="scrap"){
					this.assetStatus.push(item.value);
				}
			})
		}
		this.searches = [
			{type: "daterange", name: "购置日期", code: "boughtDateStart,boughtDateEnd", placeholder: "请选择购置日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
			{type: "input", name: "资产编码", code: "code", placeholder: "请输入资产编码", maxlength: 30, showLimit: true},
			{type: "input", name: "资产名称", code: "name", placeholder: "请输入资产名称"},
			{type: "tree-select", name: "资产分类", code: "assetCategoryIds", placeholder: "请选择资产分类", dictCode:'FamsAssetCategory',checkStrictly:true,multiple:true,dataPermissionProcess:true},
			{type: "input", name: "规格型号", code: "model", placeholder: "请输入规格型号"},
			{type: "tree-select", name: "使用部门", code: "usingDepartmentIds", placeholder: "请选择使用部门", dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true,permissionData:this.$TOOL.current.manageDeptIds()},
			{type: "selector", name: "使用人", code: "usingMenId", placeholder: "请选择使用人", dictCode:'SysUser'},
			{type: "input", name: "品牌", code: "brand", placeholder: "请输入品牌"},
			{type: "tree-select", name: "管理部门", code: "dutyDepartmentIds", placeholder: "请选择管理部门", dictCode:'SysOrganization',checkStrictly:true,multiple:true},
			{type: "select", name: "资产状态", code: "assetStatusIds", placeholder: "请选择资产状态", dictCode:'ASSET_STATUS',multiple:true,checkStrictly:true,dataPermissionProcess:true,permissionData:this.assetStatus},
			{type: "tree-select", name: "资产位置", code: "storePlaceIds", placeholder: "请选择资产位置", dictCode:'FamsPosition',checkStrictly:true,multiple:true},
		]
		await this.searchHandler();
	},
	beforeMount() {
	},
	methods: {
		buttonHandler(index, name) {
			this.$options.methods[name](this, index);
		},
		// async searchTreeHandler(data) {
		// 	let queryParams = {pathCode:data.levelCode}
		// 	this.parentLevelCode= data.levelCode;
		// 	await this.$refs.table.refresh(queryParams);
		// },

		async searchHandler() {
			let queryParams = {}
			queryParams.isContainOldScrap = this.isContainOldScrap;
			if (this.isHuaShi){
				queryParams.huaShiDate = "1";
			}
			queryParams.scrapMonth = this.scrapMonth;
			if (this.isNetValueZero) {
				queryParams.isNetValueZero = "1";
			}
			await this.$refs.table.refresh(queryParams);
		},
		columnClickHandler(name,data){
			this.$options.methods[name](this, data);
		},
		changeOld(val){
			this.isContainOldScrap = val;
			this.searchHandler()
		},
		changeNetValue(val){
			this.isNetValueZero = val;
			this.searchHandler()
		},
		changeHuaShi(val){
			this.isHuaShi = val;
			this.searchHandler()
		},
		changeScrapMonth(val){
			this.scrapMonth = val;
			this.searchHandler()
		},
		//查看
		async show1(_this, row) {
			let assetCategory = await _this.$cache.data.loadAssetCategory(row.assetCategoryId);
			try {
				_this.loading = true;
				let entity = {cardId: assetCategory.assetCardId, _editFlag: false}
				_this.$nextTick(() => {
					_this.cardPreview = false;
					_this.$refs.dataCard.open(Object.assign(entity, row));
				});
			} finally {
				_this.loading = false;
			}
		},
		//导出
		async export(_this,index) {
		  	let attachParams = {};
		  	attachParams.isContainOldScrap = _this.isContainOldScrap;
			if (_this.isNetValueZero) {
				attachParams.isNetValueZero = "1";
			}
			if (_this.isHuaShi){
				attachParams.huaShiDate = "1";
			}
			attachParams.scrapMonth = _this.scrapMonth;
			attachParams.exportType = "scrapAsset";
			let exportApi = _this.$API.asset.asset.export;
			let exTableRef = _this.$refs.table;
			let exportBtnRef = _this.$refs.button;
			let exportBtnIndex = index;
			await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);
		},
	}
}

</script>
<style scoped>

</style>
